using System;
using QFramework;

namespace QGameFramework.Tools
{
    public partial class Tool : IUtility
    {
        public void InsertSort<T>(T[] array) where T : IComparable<T>
        {
            if (array.Length <= 0)
                return;
            for (int i = 0; i < array.Length; i++)
            {
                T temp = array[i];
                int j = i - 1;
                while (j >= 0 && array[j].CompareTo(temp) > 0)
                {
                    array[j + i] = array[j];
                    j--;
                }

                array[j + i] = temp;
            }
        }

        /// <summary>
        /// 获取时间差
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public double DiffSeconds(DateTime startTime, DateTime endTime)
        {
            TimeSpan secondSpan = new TimeSpan(endTime.Ticks - startTime.Ticks);
            return secondSpan.TotalSeconds;
        }
    }
}